In Scripting, views can populate their navigation bar or toolbar area using either the original ToolBarProps object or the declarative component-based API that mirrors SwiftUI’s toolbar system. This document explains in detail how to use the Toolbar, ToolbarItem, ToolbarItemGroup, ToolbarSpacer, and DefaultToolbarItem components, including parameters, types, and usage patterns.
The toolbar property can be used in two ways:
ToolBarProps object<Toolbar> componentWhen using the component-based API, all toolbar content is declared inside a <Toolbar> container, and each item defines its placement explicitly. This provides clearer structure and more precise layout control, similar to SwiftUI.
The <Toolbar> component serves as a container for toolbar content. It does not define placement itself; instead, ToolbarItem and ToolbarItemGroup determine where items go.
ToolbarItem represents a single toolbar element placed at a specific position.
| Parameter | Type | Default | Description |
|---|---|---|---|
placement |
ToolbarItemPlacement |
automatic |
Position of the item, such as topBarLeading, navigation, primaryAction |
children |
VirtualNode |
required | The item’s content, usually a button or text |
ToolbarItemGroup allows multiple toolbar items to be grouped together in a single placement.
| Parameter | Type | Default | Description |
|---|---|---|---|
placement |
ToolbarItemPlacement |
automatic |
Placement for the entire group |
children |
multiple VirtualNodes |
required | The grouped toolbar items |
ToolbarSpacer inserts empty space in a toolbar. It can be used to fine-tune layout between items.
| Parameter | Type | Default | Description |
|---|---|---|---|
sizing |
'fixed' | 'flexible' |
flexible |
Determines whether the spacer expands or stays fixed |
placement |
ToolbarItemPlacement |
automatic |
Placement for the spacer |
flexible: Expands to fill available space.fixed: Adds a fixed separation between items.DefaultToolbarItem inserts system-provided toolbar items, such as the sidebar toggle button or search button.
| Parameter | Type | Default | Description |
|---|---|---|---|
kind |
"sidebarToggle" | "search" | "title" |
required | Specifies which system item to insert |
placement |
ToolbarItemPlacement |
automatic |
Toolbar placement |
| Method | Description |
|---|---|
toolbar={{ topBarTrailing: <Button/> }} |
Simple and declarative for straightforward scenarios |
toolbar={<Toolbar>...</Toolbar>} |
More explicit, structured, and ideal for complex layouts |
Both approaches remain fully supported. When a VirtualNode is passed, it must be a <Toolbar> component to ensure proper layout interpretation.